package mvp.demo.P;


import java.lang.ref.WeakReference;
import java.util.List;

import mvp.demo.M.IModel;
import mvp.demo.M.MainModel;
import mvp.demo.V.IView;

/**
 * Created by cjz on 2018/7/20.
 */
public class MainPresenter extends BasePresenter {


    @Override
    public void attachModel() {
        model = new MainModel();
    }


    public void getData() {

        IView view;
        if (viewRef != null && (view = viewRef.get()) != null) {
            view.showLoading();
        }

        model.business(new IModel.IModelBusinessFinishListener() {
            @Override
            public void ing() {

            }

            @Override
            public void ok(List<String> data) {
                IView v;
                if (viewRef != null && (v = viewRef.get()) != null) {
                    v.showData(data);
                    v.hideLoading();
                }
            }

            @Override
            public void error() {

            }
        });


    }

    public void showItem(String str) {
        IView view;
        if (viewRef != null && (view = viewRef.get()) != null) {
            view.showItem(str);
        }

    }

}
